package com.oracle.application.controller;


import com.oracle.application.entity.Phone;
import com.oracle.application.entity.vo.PhoneVo;
import com.oracle.application.entity.vo.R;
import com.oracle.application.service.IPhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zjc
 * @since 2021-07-06
 */
@RestController
@RequestMapping("/phone")
public class PhoneController {

    @Autowired
    private IPhoneService iPhoneService;



    @GetMapping("/page")
    public R page(Integer current, Integer pageSize, PhoneVo phoneVo){
        return this.iPhoneService.pageIphone(current,pageSize,phoneVo);
    }


    @GetMapping("/list")
    public List<Phone> list(){

        return this.iPhoneService.list();
    }

    @PostMapping("/phoneAdd")
    public R<Phone> add(@RequestBody Phone Phone){
        //接受的参数为vo 执行的添加对象为po
        this.iPhoneService.saveOrUpdate(Phone);
        return new R<Phone>(200,"ok",Phone);
    }

    @PostMapping("/phoneUpdate")
    public R<Phone> update(@RequestBody Phone phone){
        //接受的参数为vo 执行的添加对象为po
        this.iPhoneService.saveOrUpdate(phone);
        return new R<Phone>(200,"ok",phone);
    }

    @PostMapping("/Id")
    public R<Phone> getPhoneId(@RequestBody Phone phone){
        this.iPhoneService.getById(phone.getId());
        return new R<Phone>(200,"ok",phone);
    }

    @PostMapping("/phoneId")
    public R<Phone> updatePhoneId(@RequestBody Phone phone){
        this.iPhoneService.updatePhoneId(phone.getId());
        return new R<Phone>(200,"ok",phone);
    }



}
